<template>
  {{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
  {{else}}
    <AppKanBan
        :id="controlID"
        :class="classNames"
        :items="store.data"
        :selections="store.selections"
{{#if ctrl.emptyText}}
        emptyText="{{ctrl.emptyText}}"
{{/if}}
{{#if ctrl.emptyTextPSLanguageRes}}
        emptyTextPSLanguageRes="{{ctrl.emptyTextPSLanguageRes}}"
{{/if}}          
        @item-click="handleItemClick"
        @drag-change="handleDragChange"
        @item-db-click="handleItemDbClick">
    </AppKanBan>
  {{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@KANBAN}}-kanban/\{{spinalCase ctrl.codeName}}-kanban.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
import { AppKanBan } from '@components/widgets/kanban';
import { ICtrlDataAction, IContext, IParam, KanBanActionType, IKanBanAbility, IKanBanControllerParams, IKanBanController, IKanBanStore, KanBanController, createUUID, ILoadingHelper, IViewCtx } from '@/core';
import { useNavParamsBind, getCtrlClassNames, useEventBind } from '@/hooks/use-ctrl';
import { {{pascalCase ctrl.name}}ControlVO } from './{{spinalCase ctrl.codeName}}-kanban-vo';
import { model } from "./{{spinalCase ctrl.codeName}}-kanban-model";
import KanBanService from "@/core/modules/ctrl-service/kanban-service";
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    selectFirstDefault?: boolean;    
    rowActiveMode?: 0 | 1 | 2;    
    actions: ICtrlDataAction;
    "
    propsDefault="singleSelect: false,
    rowActiveMode: 2
    "    
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="KanBanActionType" ability="IKanBanAbility"}}
//  部件样式名
const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});

const handleItemClick = (row: IParam, event: MouseEvent) => {
    controller.itemClick(row, event);
}
const handleDragChange = (row: IParam, event: any) => {
    controller.dragChange(row, event);
}

const handleItemDbClick = (row: IParam, event: MouseEvent) => {
    controller.itemDbClick(row, event);
}

const controlID = createUUID();
const params: IKanBanControllerParams<KanBanActionType, IKanBanAbility> = {
    name: props.name,    
    model,
    evt,
    controlID,
    pLoadingHelper: props.pLoadingHelper,
    rowActiveMode: props.rowActiveMode,    
    singleSelect: props.singleSelect,    
    actions: props.actions,
    ctrlService: new KanBanService<{{pascalCase ctrl.name}}ControlVO>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName),
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    pViewCtx: props.pViewCtx,
    handler: (data: IKanBanStore) => { return reactive(data) }
};
{{> @macro/common/controller.hbs name="ctrl" IController="IKanBanController" store="IKanBanStore" ability="IKanBanAbility" controller="KanBanController"}}
</script>